package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;

import com.ruoyi.system.bo.TurnOverClientBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Prospects;
import com.ruoyi.system.service.IProspectsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 潜在客户Controller
 * 
 * @author tong
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/prospects/prospects")
public class ProspectsController extends BaseController
{
    @Autowired
    private IProspectsService prospectsService;

    /**
     * 查询潜在客户列表
     */
    @RequiresPermissions("prospects:prospects:list")
    @GetMapping("/list")
    public TableDataInfo list(Prospects prospects)
    {
        startPage();
            List<Prospects> list = prospectsService.selectProspectsList(prospects);
        return getDataTable(list);
    }

    /**
     * 导出潜在客户列表
     */
    @RequiresPermissions("prospects:prospects:export")
    @Log(title = "潜在客户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Prospects prospects)
    {
        List<Prospects> list = prospectsService.selectProspectsList(prospects);
        ExcelUtil<Prospects> util = new ExcelUtil<Prospects>(Prospects.class);
        util.exportExcel(response, list, "潜在客户数据");
    }

    /**
     * 获取潜在客户详细信息
     */
    @RequiresPermissions("prospects:prospects:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prospectsService.selectProspectsById(id));
    }

    /**
     * 新增潜在客户
     */
    @RequiresPermissions("prospects:prospects:add")
    @Log(title = "潜在客户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Prospects prospects)
    {
        return toAjax(prospectsService.insertProspects(prospects));
    }

    /**
     * 修改潜在客户
     */
    @RequiresPermissions("prospects:prospects:edit")
    @Log(title = "潜在客户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Prospects prospects)
    {
        return toAjax(prospectsService.updateProspects(prospects));
    }

    /**
     * 删除潜在客户
     */
    @RequiresPermissions("prospects:prospects:remove")
    @Log(title = "潜在客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prospectsService.deleteProspectsByIds(ids));
    }


    /**
     * 移交客户
     */
//    @RequiresPermissions("prospects:prospects:add")
    @Log(title = "潜在客户", businessType = BusinessType.UPDATE)
    @PostMapping("/turnOver")
    public AjaxResult turnOver(@RequestBody TurnOverClientBo turnOverClientBo)
    {
        prospectsService.turnOver(turnOverClientBo);
        return success();
    }

    /**
     * 转为正式学员
     */
    @Log(title = "潜在客户", businessType = BusinessType.UPDATE)
    @GetMapping("/toFullTrainees/{id}")
    public AjaxResult toFullTrainees(@PathVariable("id") @NotEmpty(message = "id不能为空") Long id)
    {
        prospectsService.toFullTrainees(id);
        return success();
    }




}
